package cn.edu.leetcode.其他;

public class 搜索插入位置 {
    public static void main(String[] args) {
        int[] nums = {1, 3, 5, 6};
        int target = 2;
        System.out.println(searchInsert(nums, target));
    }

    public static int searchInsert(int[] nums, int target) {
        int i = 0, j = nums.length - 1;
        int z;
        while (i <= j) {
            z = (i + j) / 2;
            if (target > nums[z]) {
                i = z + 1;
            } else {
                j = z - 1;
            }
        }
        return i;
    }
}
